#!/bin/bash

echo "=========================================="
echo "    MYNT-EYE-D1000 SDK 依赖安装脚本"
echo "=========================================="

echo "正在安装MYNT-EYE-D1000 SDK所需的依赖包..."

# 安装基本依赖
echo "1. 安装基本依赖包..."
sudo apt-get update
sudo apt-get install -y \
    build-essential \
    cmake \
    git \
    make \
    curl \
    libv4l-dev \
    libjpeg-dev \
    libgtk-3-dev \
    libusb-dev \
    libusb-1.0-0-dev \
    libudev-dev

echo "2. 设置USB设备权限..."
# 创建udev规则文件
sudo tee /etc/udev/rules.d/99-mynt-eye.rules > /dev/null <<EOF
# MYNT EYE D1000
SUBSYSTEM=="usb", ATTRS{idVendor}=="2bc5", ATTRS{idProduct}=="0401", MODE="0666", GROUP="plugdev"
SUBSYSTEM=="usb", ATTRS{idVendor}=="2bc5", ATTRS{idProduct}=="0402", MODE="0666", GROUP="plugdev"
SUBSYSTEM=="usb", ATTRS{idVendor}=="2bc5", ATTRS{idProduct}=="0403", MODE="0666", GROUP="plugdev"
EOF

# 重新加载udev规则
sudo udevadm control --reload-rules
sudo udevadm trigger

echo "3. 将用户添加到plugdev组..."
sudo usermod -a -G plugdev $USER

echo "=========================================="
echo "依赖安装完成！"
echo ""
echo "重要提示："
echo "1. 请重新插入MYNT-EYE-D1000摄像头设备"
echo "2. 您可能需要重新登录或重启系统以使组权限生效"
echo "3. 然后可以运行以下命令编译SDK："
echo "   cd /home/hwking/MYNT-EYE-D-SDK"
echo "   make build"
echo "   make install"
echo "=========================================="
